package com.fan.shop.businesslogic;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.log4j.Logger;

import com.fan.shop.domain.StockReqLine;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.StockReqLineService;

public class StockReqLineUpdateProcess extends ProcExec<Integer> {

	private static Logger logger = Logger
			.getLogger(StockReqLineUpdateProcess.class);

	private String requisitionNo;
	private String itemCode;
	private String officerCode;
	private String storeCode;
	private BigDecimal price;
	private int qty;
	private Date transactionDate;
	private String lineStatus;

	private StockReqLineService stockReqLineService;

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		StockReqLineUpdateProcess.logger = logger;
	}

	public String getRequisitionNo() {
		return requisitionNo;
	}

	public void setRequisitionNo(String requisitionNo) {
		this.requisitionNo = requisitionNo;
	}


	public String getOfficerCode() {
		return officerCode;
	}

	public void setOfficerCode(String officerCode) {
		this.officerCode = officerCode;
	}

	public String getStoreCode() {
		return storeCode;
	}

	public void setStoreCode(String storeCode) {
		this.storeCode = storeCode;
	}

	public String getItemCode() {
		return itemCode;
	}

	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public int getQty() {
		return qty;
	}

	public void setQty(int qty) {
		this.qty = qty;
	}

	public Date getTransactionDate() {
		return transactionDate;
	}

	public void setTransactionDate(Date transactionDate) {
		this.transactionDate = transactionDate;
	}

	public String getLineStatus() {
		return lineStatus;
	}

	public void setLineStatus(String lineStatus) {
		this.lineStatus = lineStatus;
	}

	public StockReqLineService getStockReqLineService() {
		return stockReqLineService;
	}

	public void setStockReqLineService(StockReqLineService stockReqLineService) {
		this.stockReqLineService = stockReqLineService;
	}

	@Override
	public Integer processImpl() {
		if(!stockReqLineService.hasStockReqLine(requisitionNo, itemCode))
		{
			setErrorMessage("Requisition itemCode: " + requisitionNo + " " + itemCode + " doesn't exist!");
			return ShopGlobalVariables.FAILED;
		}
		
		StockReqLine stockReqLine = stockReqLineService.getStockReqLine(requisitionNo, itemCode);
		stockReqLine.setStoreCode(storeCode);
		stockReqLine.setPrice(price);
		stockReqLine.setQty(qty);
		stockReqLine.setOfficerCode(officerCode);
		stockReqLine.setTransactionDate(transactionDate);
		stockReqLine.setLineStatus(lineStatus);
		
		stockReqLineService.updateStockReqLine(stockReqLine);
		
		
		return ShopGlobalVariables.SUCCESS;
	}

}
